package room

import (
	"gitee.com/game_diamond/consts"
	"gitee.com/game_diamond/session"
)

type AiRoom struct {
	course *session.CourseAIHashSession
	*Room
}

func (r *AiRoom) Init() {
	r.Room.Init()
	r.course = &session.CourseAIHashSession{
		CourseId: r.CourseId,
	}
	r.course.Init()
	r.addDelayTask()
}

func (r *AiRoom) GC() {

}

func (r *AiRoom) AddTeacher(teacherId int) error {
	if r.SessionExist(teacherId) {
		return errorSessionExist
	}
	ts := &session.TeacherAiHashSession{
		TeacherId: teacherId,
	}
	ts.Init()
	us := &UserSession{
		UserId:  teacherId,
		Actor:   consts.ActorTeacher,
		Session: ts,
	}
	r.AddSession(us)
	return nil
}

func (r *AiRoom) AddStudent(studentId int) error {
	if r.SessionExist(studentId) {
		return errorSessionExist
	}
	//init global
	gl := session.GetGlobalStudentSession(studentId)
	gl.RoomId = r.RoomId
	gl.SceneId = consts.SceneStudentCoursePrev
	gl.Save()
	//enter
	r.Enter(studentId)
	//init ai session
	ss := &session.StudentAIHashSession{
		StudentId: studentId,
	}
	ss.Init()
	us := &UserSession{
		UserId:  studentId,
		Actor:   consts.ActorStudent,
		Session: ss,
	}
	r.AddSession(us)
	return nil
}

func (r *AiRoom) GetStudentAISession(studentId int) (*session.StudentAIHashSession, error) {
	u, err := r.GetSession(studentId)
	if err != nil || u.Session == nil {
		return nil, err
	}
	if ss, ok := u.Session.(*session.StudentAIHashSession); ok {
		return ss, nil
	}
	return nil, errorSessionNotExist
}

func (r *AiRoom) addDelayTask() {
	r.DelayTask = make([]int, 0)
	r.DelayTask = append(r.DelayTask, 1)

}

func (r *AiRoom) Enter(studentId int) error {
	// do something

	r.Room.Enter(studentId)
	return nil
}

func (r *AiRoom) Leave(studentId int) error {
	// do something

	r.Room.Leave(studentId)
	return nil
}

//supply

type AiSupplyRoom struct {
	*AiRoom
}

func (r *AiSupplyRoom) Init() {

}

func (r *AiSupplyRoom) GC() {

}

func (r *AiSupplyRoom) addDelayTask() {

}
